using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class SystemSetting : MonoBehaviour {
    public static bool isPlayBgM = true;
    public static bool isPlayFightM = true;
    public static bool isPlayUIV = true;
    public static bool isPlayFightV = true;
    private Toggle mBgMusic;
    private Toggle mFightMusic;
    private Toggle mUIVoice;
    private Toggle mFightVoice;
    private static int first = 0;
	void Start () {
        mBgMusic = transform.Find("VioceSetting/BgMusic").GetComponent<Toggle>();
        mFightMusic = transform.Find("VioceSetting/FightMusic").GetComponent<Toggle>();
        mUIVoice = transform.Find("VioceSetting/UIVioce").GetComponent<Toggle>();
        mFightVoice = transform.Find("VioceSetting/FightVioce").GetComponent<Toggle>();
        mBgMusic.onValueChanged.AddListener((bool value) => OnToggleValueChanged(1, value));
        mFightMusic.onValueChanged.AddListener((bool value) => OnToggleValueChanged(2, value));
        mUIVoice.onValueChanged.AddListener((bool value) => OnToggleValueChanged(3, value));
        mFightVoice.onValueChanged.AddListener((bool value) => OnToggleValueChanged(4, value));
        mBgMusic.isOn = isPlayBgM;
        mFightMusic.isOn = isPlayFightM;
        mUIVoice.isOn = isPlayUIV;
        mFightVoice.isOn = isPlayFightV;
	}
    private void OnToggleValueChanged(int toggle, bool isPlay)
    {
        AudioController.Instance.SoundPlay(AudioPlayerName.tyandj, 0.7f);
        switch (toggle)
        {
            case 1://背景音乐播放或停止
                isPlayBgM = isPlay;
                if (!isPlayBgM)
                {
                    AudioController.Instance.BGMPause();
                    first = 1;
                }
                else if (first==1)
                {
                    AudioController.Instance.BGMPlay(AudioPlayerName.UI_Main_Loop, 0.8f);
                }
                break;
            case 2://战斗音乐播放或停止
                isPlayFightM = isPlay;
                break;
            case 3://界面音效播放或停止
                isPlayUIV = isPlay;
                break;
            case 4://战斗音效播放或停止
                isPlayFightV = isPlay;
                break;
        }
        
    }
   
}
